home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Apple Color OneScanner SDK / Scan Image 1.0 / Source / scanDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  18.5 KB  |  783 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        scanDialog.c
  4. #
  5. #        This segment contains dialog handling functions for scanning.
  6. #        (not neccessary functions)
  7. #
  8. #        Author(s):     Michael Marinkovich
  9. #                    Apple Developer Technical Support
  10. #                    marink@apple.com
  11. #
  12. #        Modification History: 
  13. #
  14. #            2/10/96        MWM     Initial coding                     
  15. #
  16. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  17. #
  18. #
  19. #        You may incorporate this sample code into your applications without
  20. #        restriction, though the sample code has been provided "AS IS" and the
  21. #        responsibility for its operation is 100% yours.  However, what you are
  22. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  23. #        after having made changes. If you're going to re-distribute the source,
  24. #        we require that you make it clear in the source that the code was
  25. #        descended from Apple Sample Code, but that you've made changes.
  26. #
  27. *************************************************************************************/
  28.  
  29. #include <Controls.h>
  30. #include <Events.h>
  31. #include <ToolUtils.h>
  32. #include <Gestalt.h>
  33. #include <OSUtils.h>
  34. #include <Palettes.h>
  35.  
  36. #include "App.h"
  37. #include "Proto.h"
  38.  
  39.  
  40. //----------------------------------------------------------------------
  41. //
  42. //    SetupAndScan - Entry point for scan sample
  43. //                 
  44. //
  45. //----------------------------------------------------------------------
  46.  
  47. void SetupAndScan(void)
  48. {
  49.     OSErr                err;
  50.     WindowRef            window;
  51.     CGrafPtr            oldPort;
  52.     GWorldPtr            theWorld;
  53.     GDHandle            oldGD;
  54.     ScStdFeaturesRec     scannerInfo;
  55.     PixMapHandle        thePix;
  56.     Rect                theRect;
  57.     DocHnd                doc;
  58.     Str255                title = "\p";
  59.     
  60.  
  61.     GetGWorld(&oldPort, &oldGD);
  62.     
  63.     err = DoNewScan(&theWorld);
  64.     
  65.     SetGWorld(oldPort, oldGD);
  66.     
  67.     if (err == noErr && theWorld != nil)
  68.     {
  69.  
  70.         window = CreateWindow(128, nil, nil, title, true, documentProc, 
  71.                                kDocKind, (WindowPtr)-1,true, nil );
  72.     
  73.         doc = (DocHnd)GetWRefCon(window);
  74.     
  75.         if (doc != nil)
  76.         {
  77.             HLock((Handle)doc);
  78.             SetGWorld((CGrafPtr)window, nil);
  79.  
  80.             (**doc).world = theWorld;
  81.             InvalRect(&(**doc).world->portRect);
  82.             AdjustScrollbars(window, true);
  83.             
  84.             HUnlock((Handle)doc);
  85.  
  86.         }
  87.     }    
  88.     else
  89.         // user cancelled - just continue
  90.         if (err == userCanceledErr)
  91.             err = noErr;    
  92.  
  93.     if (err != noErr)
  94.         HandleError(err, false);
  95.         
  96. }
  97.  
  98.  
  99. //----------------------------------------------------------------------
  100. //
  101. //    GetUserScanInfo - request the depth, resolution, and color
  102. //                      requirements of the scan and finally do the scan.    
  103. //
  104. //----------------------------------------------------------------------
  105.  
  106. OSErr GetUserScanInfo(CGrafPtr *dstPort, ScStdFeaturesRec *scannerInfo, 
  107.                       ScResPtr lineArtRes, ScResPtr halfToneRes, ScResPtr grayScaleRes, 
  108.                       ScResPtr biLevelColorRes, ScResPtr fullColorRes, 
  109.                       ScHalfTonePtr halfToneNames, UserSettingsPtr userSettings)
  110. {
  111.     OSErr                err = noErr;
  112.     ScTPUADFInfo         TPUADFInfo;
  113.     ScStdFeaturesRec     newScannerInfo;
  114.     DialogPtr            dialog;
  115.     Handle                item;
  116.     ModalFilterUPP        modalUPP;
  117.     Str255                str;
  118.     Rect                box;
  119.     short                itemType;
  120.     short                resItem;
  121.     short                itemHit;
  122.     short                selection;
  123.     Boolean                done = false;
  124.     Boolean             ADF;
  125.     Boolean             TPU;
  126.     
  127.     
  128.     SetCursor(&qd.arrow);
  129.  
  130.     if (err == noErr)
  131.     {
  132.         dialog = GetNewDialog(rNewScanDlg, nil, (WindowPtr) -1);
  133.         
  134.         if (dialog != nil) 
  135.         {
  136.             ShowWindow(dialog);
  137.             SetPort(dialog);
  138.                         
  139.             SetDialogDefaultItem(dialog, ok);
  140.             
  141.             newScannerInfo = *scannerInfo;
  142.  
  143.             err = AdjustScanDialogItems(dialog, newScannerInfo,
  144.                                         lineArtRes, halfToneRes, grayScaleRes, 
  145.                                         biLevelColorRes, fullColorRes, halfToneNames);
  146.  
  147.             modalUPP = NewModalFilterProc(StdDialogEventFilter);
  148.  
  149.             // loop until user selects OK or CANCEL
  150.             while (!done) 
  151.             {
  152.                 ModalDialog(modalUPP, &itemHit );
  153.                 done = (itemHit == cancel || itemHit == ok);
  154.                 
  155.                 if (itemHit == kColorPopup || itemHit == kSourcePopup)
  156.                 {
  157.                     if (itemHit == kSourcePopup)
  158.                     {
  159.                         err = GetInputMethods(&ADF, &TPU, &TPUADFInfo);
  160.                         GetDItem (dialog, kSourcePopup, &itemType, &item, &box);
  161.                         selection = GetControlValue((ControlRef)item);
  162.                         
  163.                         // change rect size according to which input method user has
  164.                         // chosen. If it is ADF of TPU then get the width and height
  165.                         // from the TPUADFInfo structure obtained from GetInputMethods.
  166.                         switch (selection)
  167.                         {
  168.                             case kSourceFlatbedItem:
  169.                                 newScannerInfo = *scannerInfo;
  170.                                 break;
  171.                             
  172.                             case kSourceADFItem:
  173.                                 newScannerInfo.scanWidthNum = TPUADFInfo.ADFScanWidthNum;
  174.                                 newScannerInfo.scanWidthDen = TPUADFInfo.ADFScanWidthDen;
  175.                                 newScannerInfo.scanLengthNum = TPUADFInfo.ADFScanLengthNum;
  176.                                 newScannerInfo.scanLengthDen = TPUADFInfo.ADFScanLengthDen;
  177.                                 break;
  178.                             
  179.                             case kSourceTPUItem:
  180.                                 newScannerInfo.scanWidthNum = TPUADFInfo.TPUScanWidthNum;
  181.                                 newScannerInfo.scanWidthDen = TPUADFInfo.TPUScanWidthDen;
  182.                                 newScannerInfo.scanLengthNum = TPUADFInfo.TPUScanLengthNum;
  183.                                 newScannerInfo.scanLengthDen = TPUADFInfo.TPUScanLengthDen;
  184.                                 break;
  185.                         }
  186.                     }
  187.                     
  188.                     err = AdjustScanDialogItems(dialog, newScannerInfo,
  189.                                                 lineArtRes, halfToneRes, grayScaleRes, 
  190.                                                 biLevelColorRes, fullColorRes, halfToneNames);
  191.  
  192.                 }
  193.             }
  194.             
  195.             if (itemHit == ok)
  196.             {
  197.                 // set input method
  198.                 GetDItem (dialog, kSourcePopup, &itemType, &item, &box);
  199.                 
  200.                 userSettings->inputMethod = GetControlValue((ControlRef)item);
  201.             
  202.                 // if user selected TPU we need to get the transparency options
  203.                 if (userSettings->inputMethod == kSourceTPUItem)
  204.                 {
  205.                     err = GetUserTPUSettings(&userSettings->TPUFilm, &userSettings->TPUVendor);
  206.                     userSettings->TPULight = true;
  207.                 } 
  208.                 else 
  209.                 {
  210.                     // set the TPU settings to false if we are using the flatbed
  211.                     userSettings->TPUFilm = 0;
  212.                     userSettings->TPULight = 0;
  213.                     userSettings->TPUVendor = 0;
  214.                 }
  215.                 
  216.                 // set compMode...color, grayscale, etc..
  217.                 GetDItem (dialog, kColorPopup, &itemType, &item, &box);
  218.                 
  219.                 selection = GetControlValue((ControlRef)item) - 1;
  220.                 
  221.                 // adjust final value to reflect the lack of a Bi-Level popup item
  222.                 if (selection == scBiLevelColor)
  223.                     selection++;
  224.                     
  225.                 userSettings->compMode = selection;
  226.                 
  227.                 // set scan resolution
  228.                 GetDItem (dialog, kResolutionPopup, &itemType, &item, &box);
  229.                 resItem = GetControlValue((ControlRef)item);
  230.                 
  231.                 userSettings->resolution = GetCompModeResolution(userSettings->compMode, resItem - 1, 
  232.                                                                  lineArtRes, halfToneRes, grayScaleRes, 
  233.                                                                    biLevelColorRes, fullColorRes);
  234.                 
  235.                 // get height and width from dialog items
  236.                 GetDItem (dialog, kHeightItem, &itemType, &item, &box);
  237.                 if (item != nil)
  238.                 {
  239.                     GetDialogItemText(item, str);
  240.                     StringToNum(str, &userSettings->height);
  241.                 }
  242.                 
  243.                 GetDItem (dialog, kWidthItem, &itemType, &item, &box);
  244.                 if (item != nil)
  245.                 {
  246.                     GetDialogItemText(item, str);
  247.                     StringToNum(str, &userSettings->width);
  248.                 }
  249.                 
  250.                 // just set these items to middle ground
  251.                 userSettings->brightness = 128;
  252.                 userSettings->contrast = 128;
  253.                 userSettings->ditherPattern = 0;
  254.                 
  255.                 // make sure brightness & contrast are not greater than max values
  256.                 if (userSettings->brightness > scannerInfo->composition[userSettings->compMode].brightnessMax)
  257.                     userSettings->brightness = scannerInfo->composition[userSettings->compMode].brightnessMax;
  258.  
  259.                 if (userSettings->contrast > scannerInfo->composition[userSettings->compMode].contrastMax)
  260.                     userSettings->contrast = scannerInfo->composition[userSettings->compMode].contrastMax;
  261.                 
  262.                 // if user selected HalfTone we need to get the pattern
  263.                 if (userSettings->compMode == scHalfTone)
  264.                     err = GetUserHalfTone(&userSettings->ditherPattern, halfToneNames, *scannerInfo);
  265.  
  266.                                                 
  267.             }
  268.             // user hit cancel - make sure we didn't already have an err pending.
  269.             else
  270.                 if (err == noErr) err = userCanceledErr;
  271.             
  272.             DisposeRoutineDescriptor(modalUPP);
  273.             DisposeDialog(dialog);
  274.             
  275.         }
  276.         
  277.     }
  278.         
  279.     return err;
  280.     
  281. }    
  282.  
  283.  
  284.  
  285. //----------------------------------------------------------------------
  286. //
  287. //    AdjustScanDialogItems - Get scanner capabilities and enable/disable
  288. //                              dialog items accordingly.
  289. //
  290. //----------------------------------------------------------------------
  291.  
  292. OSErr AdjustScanDialogItems(DialogRef dialog, ScStdFeaturesRec scannerInfo, 
  293.                             ScResPtr lineArtRes, ScResPtr halfToneRes, 
  294.                             ScResPtr grayScaleRes, ScResPtr biLevelColorRes, 
  295.                             ScResPtr fullColorRes, ScHalfTonePtr halfToneNames)
  296. {
  297.     OSErr                    err = noErr;
  298.     Handle                    item;
  299.     MenuRef                    menu;
  300.     PopupPrivateDataHandle    popupData;
  301.     ScTPUADFInfo            TPUADFInfo;
  302.     Rect                    box;
  303.     Str255                    str;
  304.     short                    res;
  305.     short                    itemType;
  306.     short                    menuItems;
  307.     short                    value;
  308.     short                    i;
  309.     Boolean                 ADF;
  310.     Boolean                    TPU;
  311.     
  312.     // source input method
  313.     GetDItem (dialog, kSourcePopup, &itemType, &item, &box);
  314.     if (item != nil)
  315.     {
  316.         popupData = (PopupPrivateDataHandle)(**(ControlRef)item).contrlData;
  317.         if (popupData != nil)
  318.             menu = (**popupData).mHandle;
  319.         
  320.         if (menu != nil)
  321.         {
  322.             // disable ADF first
  323.             DisableItem(menu, kSourceADFItem);
  324.             DisableItem(menu, kSourceTPUItem);
  325.  
  326.             err = GetInputMethods(&ADF, &TPU, &TPUADFInfo);
  327.             if (err == noErr)
  328.             {
  329.                 if (ADF)
  330.                     EnableItem(menu, kSourceADFItem);
  331.                 else
  332.                 {
  333.                     if (TPU)
  334.                         EnableItem(menu, kSourceTPUItem);
  335.                 }        
  336.     
  337.             }
  338.             else
  339.                 err = noErr;
  340.         }        
  341.  
  342.     }
  343.         
  344.     // get current compMode method from popup
  345.     GetDItem (dialog, kColorPopup, &itemType, &item, &box) ;
  346.     if (item)
  347.         value = GetControlValue((ControlRef)item);
  348.     
  349.     // get popup for resolutions
  350.     GetDItem (dialog, kResolutionPopup, &itemType, &item, &box) ;
  351.     if (item)
  352.     {
  353.         popupData = (PopupPrivateDataHandle)(**(ControlRef)item).contrlData; 
  354.         menu = (**popupData).mHandle ;
  355.  
  356.         menuItems = CountMItems(menu);
  357.         DeleteMenuItem(menu, 0);
  358.  
  359.         // clear items from menu so we can rebuild
  360.         for (i = 0; i < menuItems + 1; i++)
  361.              DeleteMenuItem(menu, 1);
  362.         
  363.         // subtract one to access zero based array 
  364.         value--;
  365.         
  366.         // since there is not a BiLevelColor item in the list increment
  367.         // the value to indicate that we actually wanted color
  368.         if (value == scBiLevelColor)
  369.             value++;
  370.  
  371.         menuItems = scannerInfo.composition[value].resElements;
  372.         
  373.         // fill menu with new resolutions
  374.         for (i = 0; i < menuItems; i++)
  375.         {
  376.             res = GetCompModeResolution(value, i, lineArtRes, 
  377.                                         halfToneRes, grayScaleRes, 
  378.                                         biLevelColorRes, fullColorRes);
  379.                                                 
  380.             NumToString(res, str);
  381.             if (i == 0)
  382.                 InsertMenuItem(menu, str, 0);
  383.             else
  384.                 InsertMenuItem(menu, str, i);
  385.         }
  386.         
  387.         SetControlValue((ControlRef)item, 1);    
  388.         InvalRect(&box);
  389.     
  390.     }
  391.  
  392.     // set height text item
  393.     GetDialogItem(dialog, kHeightItem, &itemType, &item, &box);
  394.     NumToString((72L * scannerInfo.scanLengthNum) / scannerInfo.scanLengthDen, str);
  395.     SetDialogItemText(item, str);
  396.  
  397.     // set width text item
  398.     GetDialogItem(dialog, kWidthItem, &itemType, &item, &box);
  399.     NumToString((72L * scannerInfo.scanWidthNum) / scannerInfo.scanWidthDen, str);
  400.     SetDialogItemText(item, str);
  401.     
  402.     SelectDialogItemText(dialog, kHeightItem, 0, 32767);
  403.  
  404.     return err;
  405.     
  406. }
  407.  
  408.  
  409.  
  410. //----------------------------------------------------------------------
  411. //
  412. //    GetCompModeResolution - get resolution from resPtr specified
  413. //                              by compMode.
  414. //
  415. //----------------------------------------------------------------------
  416.  
  417. long GetCompModeResolution(short compMode, short item, ScResPtr lineArtRes, 
  418.                            ScResPtr halfToneRes, ScResPtr grayScaleRes, 
  419.                            ScResPtr biLevelColorRes, ScResPtr fullColorRes)
  420. {
  421.     long        res;
  422.                             
  423.     switch (compMode)
  424.     {
  425.         case scLineArt:
  426.             res = *(lineArtRes[item]);
  427.             break;
  428.         
  429.         case scHalfTone:
  430.             res = *(halfToneRes[item]);
  431.             break;
  432.         
  433.         case scGrayScale:
  434.             res = *(grayScaleRes[item]);
  435.             break;
  436.             
  437.         case scBiLevelColor:
  438.             res = *(biLevelColorRes[item]);
  439.             break;
  440.  
  441.         case scFullColor:
  442.             res = *(fullColorRes[item]);
  443.             break;
  444.             
  445.         default:
  446.             res = 0;
  447.             break;    
  448.     }
  449.  
  450.     return res;
  451.  
  452. }
  453.  
  454.  
  455. //----------------------------------------------------------------------
  456. //
  457. //    GetUserHalfTone - ask user what halftone to use
  458. //
  459. //
  460. //----------------------------------------------------------------------
  461.  
  462. OSErr GetUserHalfTone(short *selection, ScHalfTonePtr halfToneNames, 
  463.                       ScStdFeaturesRec scannerInfo)
  464. {
  465.     OSErr                err = noErr;
  466.     DialogPtr            dialog;
  467.     ModalFilterUPP        modalUPP;
  468.     Handle                item;
  469.     Rect                box;
  470.     short                itemType;
  471.     short                resItem;
  472.     short                itemHit;
  473.     Str255                str;
  474.     Boolean                done = false;
  475.     
  476.     dialog = GetNewDialog(rHalfToneDlg, nil, (WindowPtr) -1);
  477.     
  478.     if (dialog != nil) 
  479.     {
  480.         ShowWindow(dialog);
  481.         SetPort(dialog);
  482.                     
  483.         SetDialogDefaultItem(dialog, ok);
  484.         
  485.         err = AdjustHalfToneItems(dialog, halfToneNames, scannerInfo);
  486.  
  487.         modalUPP = NewModalFilterProc(StdDialogEventFilter);
  488.  
  489.         while (!done) 
  490.         {
  491.             ModalDialog(modalUPP, &itemHit);
  492.             done = (itemHit == cancel || itemHit == ok);
  493.             
  494.         }
  495.         
  496.         if (itemHit == ok)
  497.         {
  498.             // set HalfTone Pattern
  499.             GetDItem (dialog, kHalfTonePopup, &itemType, &item, &box);;
  500.             *selection = GetControlValue((ControlRef)item);
  501.         }
  502.         
  503.         // user hit cancel - make sure we didn't already have an err pending.
  504.         else
  505.             if (err == noErr) err = userCanceledErr;
  506.             
  507.         DisposeRoutineDescriptor(modalUPP);
  508.         DisposeDialog(dialog);
  509.         
  510.     }
  511.         
  512.         
  513.     return err;
  514.     
  515. }
  516.  
  517.  
  518. //----------------------------------------------------------------------
  519. //
  520. //    AdjustHalfToneItems - adjust HalfTone names in popup
  521. //
  522. //
  523. //----------------------------------------------------------------------
  524.  
  525. OSErr AdjustHalfToneItems(DialogRef dialog, ScHalfTonePtr halfToneNames,
  526.                           ScStdFeaturesRec scannerInfo)
  527. {
  528.     OSErr                    err = noErr;
  529.     Handle                    item;
  530.     MenuRef                    menu;
  531.     PopupPrivateDataHandle    popupData;
  532.     Rect                    box;
  533.     Str255                    str;
  534.     short                    res;
  535.     short                    itemType;
  536.     short                    menuItems;
  537.     short                    i;
  538.  
  539.     
  540.     // get popup for HalfTones
  541.     GetDItem (dialog, kHalfTonePopup, &itemType, &item, &box) ;
  542.     if (item)
  543.     {
  544.         popupData = (PopupPrivateDataHandle)(**(ControlRef)item).contrlData; 
  545.         menu = (**popupData).mHandle ;
  546.  
  547.         menuItems = CountMItems(menu);
  548.         DeleteMenuItem(menu, 0);
  549.  
  550.         // clear items from menu so we can rebuild
  551.         for (i = 0; i < menuItems + 1; i++)
  552.              DeleteMenuItem(menu, 1);
  553.         
  554.         menuItems = scannerInfo.composition[scHalfTone].halfToneElements;
  555.         
  556.         // fill menu with new resolutions
  557.         for (i = 0; i < menuItems; i++)
  558.         {
  559.             
  560.             pstrcpy(str, (unsigned char *)halfToneNames[i]);
  561.                                 
  562.             if (i == 0)
  563.                 InsertMenuItem(menu, str, 0);
  564.             else
  565.                 InsertMenuItem(menu, str, i);
  566.         }
  567.         
  568.         SetControlValue((ControlRef)item, 1);    
  569.         InvalRect(&box);
  570.     
  571.     }
  572.  
  573.     return err;
  574.  
  575. }
  576.  
  577.  
  578. //----------------------------------------------------------------------
  579. //
  580. //    GetUserTPUSettings - ask the user for transparency settings.
  581. //
  582. //
  583. //----------------------------------------------------------------------
  584.  
  585. OSErr GetUserTPUSettings(short *TPUFilm, short *TPUVendor)
  586. {
  587.     OSErr                err = noErr;
  588.     DialogPtr            dialog;
  589.     ModalFilterUPP        modalUPP;
  590.     Handle                item;
  591.     Rect                box;
  592.     short                itemType;
  593.     short                resItem;
  594.     short                itemHit;
  595.     short                temp;
  596.     Str255                str;
  597.     Boolean                done = false;
  598.     
  599.     dialog = GetNewDialog(rTransparentDlg, nil, (WindowPtr) -1);
  600.     
  601.     if (dialog != nil) 
  602.     {
  603.         ShowWindow(dialog);
  604.         SetPort(dialog);
  605.                     
  606.         SetDialogDefaultItem(dialog, ok);
  607.         
  608.         SetRadioValue(dialog, kTPUPositive, 1);
  609.         SetRadioValue(dialog, kTPUNegative, 0);
  610.         
  611.         modalUPP = NewModalFilterProc(StdDialogEventFilter);
  612.  
  613.         while (!done) 
  614.         {
  615.             ModalDialog(modalUPP, &itemHit);
  616.             done = (itemHit == cancel || itemHit == ok);
  617.             
  618.             if (itemHit == kTPUPositive || itemHit == kTPUNegative)
  619.             {
  620.                 SetNotRadioValue(dialog, kTPUPositive);
  621.                 SetNotRadioValue(dialog, kTPUNegative);
  622.             }
  623.                         
  624.         }
  625.         
  626.         if (itemHit == ok)
  627.         {
  628.             // set TPU NP setting
  629.             GetDItem(dialog, kTPUPositive, &itemType, &item, &box);
  630.             *TPUFilm = !GetControlValue((ControlRef)item);
  631.                 
  632.             // set film vendor
  633.             GetDItem(dialog, kTPUFilmPopup, &itemType, &item, &box);
  634.             *TPUVendor = GetControlValue((ControlRef)item) - 1;
  635.         }
  636.         
  637.         // user hit cancel - make sure we didn't already have an err pending.
  638.         else
  639.             if (err == noErr) err = userCanceledErr;
  640.             
  641.         DisposeRoutineDescriptor(modalUPP);
  642.         DisposeDialog(dialog);
  643.         
  644.     }
  645.         
  646.         
  647.     return err;
  648.     
  649. }
  650.  
  651.  
  652. //----------------------------------------------------------------------
  653. //
  654. //    StdDialogEventFilter - 
  655. //                 
  656. //
  657. //----------------------------------------------------------------------
  658.  
  659. pascal Boolean StdDialogEventFilter(DialogPtr dialog, EventRecord *event, short *itemHit)
  660. {
  661.     OSErr                err;
  662.     CGrafPtr            oldPort;
  663.     GDHandle            oldGD;
  664.     WindowRef            window;
  665.     ControlHandle        slider = nil;
  666.     ModalFilterUPP        modalProc;
  667.     Handle                item;
  668.     Rect                itemRect;
  669.     short                itemType;
  670.     short                key;
  671.     short                thePart;
  672.     short                i;
  673.     Boolean                accepted = false;
  674.  
  675.  
  676.     GetGWorld(&oldPort, &oldGD);
  677.     SetGWorld((CGrafPtr)dialog, nil);
  678.     
  679.     switch(event->what) 
  680.     {
  681.         case keyDown:
  682.         case autoKey:
  683.             key = event->message & charCodeMask;
  684.             accepted = false;
  685.             break;
  686.  
  687.         case updateEvt:
  688.             if (event->message != (long)dialog) // in case a screen saver activates.
  689.             {
  690.                 CustomWindowEvent(kUpdateProc,(WindowPtr)event->message,nil);
  691.                 SetCursor(&qd.arrow);
  692.             }
  693.             
  694.             if (event->message == (long)dialog)     // in case a screen saver activates.
  695.             {
  696.                 UpdateDialog(dialog, dialog->visRgn);                
  697.                 SetCursor(&qd.arrow);
  698.  
  699.             }    
  700.             break;
  701.             
  702.         case mouseDown:    
  703.             thePart = FindWindow(event->where,&window);
  704.  
  705.             switch(thePart) 
  706.             {
  707.                 case inContent:
  708.                     break;
  709.  
  710.                 case inSysWindow:
  711.                     SysBeep(30);
  712.                     break;
  713.  
  714.                 case inDrag:
  715.                     if (window == dialog) 
  716.                     {
  717.                         DragWindow(dialog, event->where, &qd.screenBits.bounds);
  718.                         accepted = true;
  719.                     }
  720.                     break;
  721.             }
  722.             break;        
  723.  
  724.     }
  725.         
  726.     if (!accepted) 
  727.     {
  728.         err = GetStdFilterProc(&modalProc);
  729.         if (err == noErr)
  730.         {
  731.             accepted = CallModalFilterProc(modalProc, dialog, event, itemHit);
  732.             DisposeRoutineDescriptor(modalProc);
  733.         }    
  734.     }
  735.     
  736.     SetGWorld(oldPort, oldGD);
  737.     
  738.     return(accepted);
  739.  
  740. }
  741.  
  742.  
  743. //----------------------------------------------------------------------
  744. //
  745. //    SetRadioValue - 
  746. //                 
  747. //
  748. //----------------------------------------------------------------------
  749.  
  750. void SetRadioValue(DialogRef dialog, short whichItem, short value)
  751. {
  752.     Handle                item;
  753.     Rect                box;
  754.     short                itemType;
  755.     
  756.     GetDItem (dialog, whichItem, &itemType, &item, &box);
  757.     SetControlValue((ControlRef)item, value);
  758.     
  759.  
  760. }
  761.  
  762. //----------------------------------------------------------------------
  763. //
  764. //    SetNotRadioValue - 
  765. //                 
  766. //
  767. //----------------------------------------------------------------------
  768.  
  769. void SetNotRadioValue(DialogRef dialog, short whichItem)
  770. {
  771.     Handle                item;
  772.     Rect                box;
  773.     short                itemType;
  774.     short                value;
  775.     
  776.     GetDItem (dialog, whichItem, &itemType, &item, &box);
  777.     value = GetControlValue((ControlRef)item);
  778.     
  779.     SetControlValue((ControlRef)item, !value);
  780.  
  781.  
  782. }
  783.